var wxdirectpay = require('../../utils/pay.js')
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userPayList: [],
    loadingMoreHidden: true,
    currPage: 1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getUserDirectPayList();
  },

  //获取当面付订单列表
  getUserDirectPayList: function () {
    var that = this;
    wx.request({
      url: app.globalData.host + "/api/Order/GetUserDirectPayList?storeId=" + app.globalData.storeId + "&uid=" + app.globalData.userInfo.Uid + "&pageSize=8&pageNumber=" + that.data.currPage,
      success: function (res) {
        if (res.data.Code == 0) {
          var userList = res.data.Data.OrderList
          if (that.data.currPage != 1) {
            var preGoods = that.data.userPayList
            userList = preGoods.concat(userList);
          }
          that.setData({
            userPayList: userList,
            loadingMoreHidden: res.data.Data.PageModel.HasNextPage
          })
        }
      },
    })
  },

  loadMore: function (e) {
    var that = this;
    if (!that.data.loadingMoreHidden) return;
    var currPage = that.data.currPage;
    that.setData({
      currPage: currPage + 1
    })
    that.getUserDirectPayList();
  },

  //取消支付
  cancelBtn: function (e) {
    var that = this;
    let pid = e.currentTarget.dataset.pid;
    wx.showModal({
      title: '提示',
      content: '是否确认取消支付',
      success: function (res) {
        if (res.confirm) {
          wx.request({
            url: app.globalData.host + "/api/Order/CancelDirectPayOrder?pid=" + pid,
            success: function (res) {
              if (res.data.Code == 0) {
                wx.showToast({
                  title: '取消成功',
                })
                that.getUserDirectPayList();
              }
            },
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },

  //继续支付topayBtn
  topayBtn: function (e) {
    let pid = e.currentTarget.dataset.pid//订单
    wxdirectpay.wxdirectpay(app, pid, "/pages/payFaceList/index");
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  }
})